package controller;
import bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;

@Controller     //声明是springmvc组件，以便接口被扫描
public class ErrorImpl implements Error{
    @RequestMapping(value = "/error",produces = "application/json;charset=UTF-8")
    @ResponseBody   //自定义返回，不再找jsp
    public String error(HttpServletResponse resp){
        resp.setStatus(404);
        return "{\"code\":404,\"msg\":\"Server Error\"}";
    }
    @RequestMapping(value = "/",produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String get(String username){
        return "{\"code\":200,\"username\":\""+username+"\"}";
    }
    @RequestMapping(value = "/form",produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String form(String username){
        return "{\"code\":200,\"username\":\""+username+"\"}";
    }
    @RequestMapping(value = "/json1",produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String json1(@RequestBody String username){
        return "{\"code\":200,\"username\":\""+username+"\"}";
    }
    @RequestMapping(value = "/json2",produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String json2(@RequestBody User u){
        return "{\"code\":200,\"username\":\""+u.username+"\"}";
    }
}
